package com.tledu.spring.core.entity;

import com.tledu.spring.core.constants.CommonConstants;
import lombok.Data;

/**
 * @Author: rupert-tears
 * @Date: Created in 21:59 2021/7/2
 * @Description: 优秀的人都在孤独的翻山越岭！
 *
 * 相应前台结果集类库
 *      200 标识请求成功
 *      300 标识请求失败
 * 属性集：
 *      是否成功
 *      状态码
 *      相应信息
 *      传递数据
 */
@Data
public class AjaxResult<T> {
    private Boolean success;
    private Integer code;
    private String msg;
    private T data;

    /**
     * 请求成功 200
     * @param data 数据
     */
    public AjaxResult(T data) {
        this.success = true;
        this.code = CommonConstants.AJAX_RESULT_MSG_SUCCESS_CODE;
        this.msg = CommonConstants.AJAX_RESULT_MSG_SUCCESS;
        this.data = data;
    }

    /**
     * 请求失败
     * @param code 300
     * @param msg 响应信息
     */
    public AjaxResult(Integer code, String msg) {
        this.success = false;
        this.code = CommonConstants.AJAX_RESULT_MSG_FAIL_CODE;
        this.msg = CommonConstants.AJAX_RESULT_MSG_FAIL;
    }


    /**
     * 请求成功
     * @param msg 描述信息
     */
    public AjaxResult(String msg) {
        this.success = true;
        this.code =  CommonConstants.AJAX_RESULT_MSG_SUCCESS_CODE;
        this.msg = msg;
    }

    /**
     * 无意义返回值 成功请求
     * @param code 0
     */
    public AjaxResult(Integer code) {
        this.success = true;
        this.code = code;
        this.msg = CommonConstants.AJAX_RESULT_MSG_SUCCESS;
        this.data = data;
    }
}

